import request from '@/utils/request'
import { baseUrl } from '@/config/env';


//新增编辑
export const save = (row) => {
  return request({
    url: baseUrl+'/rest/article/editItem',
    method: 'post',
    headers:{'content-type':'application/json;charset=UTF-8'},
    data: row
  })
}

//获取文章详情
export const getArticleDetail = (id) => {
  return request({
    url: `${baseUrl}/rest/article/detail/${id}`,
    method: 'get',
  })
}

//获取上传图片地址
export const getImgInfo = (fileId) => {
  return request({
    url: `${baseUrl}/rest/common/preview/${fileId}`,
    method: 'get',
  })
}

//获取素材列表
export const getMaterialList = (page,limit,status) => {
	var params = {page:page,limit:limit}
	if(status == 0 || status == 1){
		params["status"] = status;
	}

  	return request({
    	url: baseUrl+'/rest/material/list',
    	method: 'get',
    	params: params
  	})
}


//获取百度accessToken
export const getBaiduAccessToken = () => {
  return request({
    url: '/baiduApi/oauth/2.0/token',
    params:{
      grant_type:'client_credentials',
      client_id:'EAG555BGwc966fZ14pCXz1Rm',
      client_secret:'veuo7qroPGOlvPqYKXMEMhlKKvut4TGv',
    },
    method: 'get',
  })
}

//获取热点
export const bdApiHotList = (access_token,domain) => {
  return request({
    url: '/baiduApi/rpc/2.0/creation/v1/hot_list/domain',
    headers:{'content-type':'application/json'},
    params:{
      access_token:access_token,
      charset:'UTF-8'
    },
    data:{
      domain:domain
    },
    method: 'post',
  })
}

//baidu接口文本纠错
export const ecnet = (text) => {
  return request({
    url: baseUrl+'/rest/baidu/ecnet',
    method: 'get',
    params: {
      text
    }
  })
}

//baidu接口文章标签
export const keyword = (title,content) => {
  return request({
    url: baseUrl+'/rest/baidu/keyword',
    method: 'get',
    params: {
      title,
      content
    }
  })
}


//baidu接口文章分类
export const topic = (title,content) => {
  return request({
    url: baseUrl+'/rest/baidu/topic',
    method: 'get',
    params: {
      title,
      content
    }
  })
}

//baidu接口文章摘要
export const summary = (title,content,max_summary_len) => {
  return request({
    url: baseUrl+'/rest/baidu/newsSummary',
    method: 'get',
    params: {
      title,
      content,
      max_summary_len
    }
  })
}

//素材库图片添加到文章
export const imgToArticle = (fileIds) => {
  return request({
    url:baseUrl+'/rest/material/article/select',
    method:'post',
    data:{
      fileIds
    }
  })
}